import request from "@/utils/request";
import type { IResponseBody } from "./userApi";

export function findStudentAll(
  classId: number | string,
  stuId: number | string
): Promise<IResponseBody> {
  return request.get("/hw/stu", {
    params: {
      classId,
      stuId,
    },
  });
}

export function findClassAll(classId: number | string): Promise<IResponseBody> {
  return request.get("/hw/class", {
    params: {
      classId,
    },
  });
}

/**
 * 学生上传作业
 * @param file
 * @param stu_id
 * @param class_id
 * @param home_work_id
 * @returns
 */
export function studentHWUpload(file, stu_id, class_id, home_work_id) {
  const formData = new FormData();
  formData.append("file", file);
  formData.append("stu_id", stu_id);
  formData.append("class_id", class_id);
  formData.append("home_work_id", home_work_id);
  return request.post("/hw/stu/upload", formData, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

// 查找班级作业
export function getHWClassAll(id: number): Promise<IResponseBody> {
  return request.get(`/hw/class?classId=${id}`);
}

export function getHWStudentAll(
  classId: string,
  homeWorkId: string
): Promise<IResponseBody<[]>> {
  return request.get(`/hw/all`, {
    params: {
      classId: classId,
      homeWorkId: homeWorkId,
    },
  });
}

// {
//   "class_id": 18,
//   "stu_id": 1,
//   "stu_home_work_id": 9,
//   "msg": "写的很好，下次别写了",
//   "remark_time": "凌晨3:00"
// }

interface IRemark {
  class_id: number;
  stu_id: number;
  stu_home_work_id: string;
  msg: string;
  remark_time: string;
}

export function setStudentHwRemark(data: IRemark): Promise<IResponseBody> {
  return request.post(`/hw/stu/remark`, data);
}
